package com.kai.spring.demo;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Created by wukai on 07/07/2017.
 */
@Component
public class DemoAware implements ApplicationContextAware {


    /**
     * spring上下文中.
     */
    private static ApplicationContext applicationContext;

    /**
     * 从spring上下文中的bean的id获取bean对象.
     *
     * @param beanID springBean对象id
     * @return Object
     */
    public static Object getBean(String beanID) {
        return applicationContext.getBean(beanID);
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        DemoAware.applicationContext = applicationContext;
    }
}
